<template>
    <div>
        <!-- 该文件是柱状图模板 -->
        <div id="bar_wrap" style="width:100%;height:350px"></div>
    </div>
</template>

<script>
export default {
    props: {
        title: {},
        xArr: {
            type: Array
        },
        barData: {
            type: Array
        }
    },
    mounted() {
        // console.log(111)
        this.initBar()
    },
    watch: {
        barData() {
            this.initBar()
        }
    },
    methods: {
        initBar() {
            console.log(this.$echarts)
            // 基于准备好的dom，初始化echarts实例
            var myChart = this.$echarts.init(document.getElementById('bar_wrap'));
            //设置配置项
            var option = {
                title: {
                    text: '统计',
                    textStyle: {
                        color: '#fff'
                    }
                },
                textStyle: {
                    color: '#fff',
                    fontWeight: 'bolder'
                },
                xAxis: {
                    type: 'category',
                    data: this.xArr
                },
                yAxis: {
                    type: 'value'
                },
                legend: {
                    // orient: 'vertical',
                    top:'top'
                },
                series: [
                    {
                        name:'人数',
                        data: this.barData,
                        type: 'bar',
                        showBackground: true,
                        backgroundStyle: {
                            color: 'rgba(180, 180, 180, 0.2)'
                        }
                    }
                ]
            }
            // 绘制图表
            myChart.setOption(option);
        }
    }
}
</script>

<style lang="less" scoped></style>